package org.linlinjava.litemall.db.service;


import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallWantBuyMapper;
import org.linlinjava.litemall.db.domain.LitemallWantBuy;
import org.linlinjava.litemall.db.domain.LitemallWantBuyExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class LitemallWantbuyAuditService {

    @Resource
    private LitemallWantBuyMapper wantBuyMapper;

    @Autowired
    private LitemallWantbuyService wantbuyService;

    public List<LitemallWantBuy> list (String status, String userType, String sort, String order, Integer page, Integer limit, boolean selectAll){
        LitemallWantBuyExample example = new LitemallWantBuyExample();
        LitemallWantBuyExample.Criteria criteria = example.createCriteria();

        if (!StringUtils.isEmpty(status)){
            criteria.andStatusEqualTo(Byte.valueOf(status));
        }

        criteria.andDeletedEqualTo((byte) 0);
        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }

        PageHelper.startPage(page, limit);


        return wantbuyService.selectByExample(example);
    }

    public void updateById(LitemallWantBuy wantBuy){
        wantBuy.setUpdateTime(LocalDateTime.now());
        wantbuyService.updateByPrimaryKeySelective(wantBuy);
    }

    /**
     * 获取待审核总数
     */
    public int count(){
        LitemallWantBuyExample example = new LitemallWantBuyExample();
        LitemallWantBuyExample.Criteria criteria = example.createCriteria();

        criteria.andStatusEqualTo((byte) 1);
        criteria.andDeletedEqualTo((byte) 0);
        return (int) wantBuyMapper.countByExample(example);
    }


}
